﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using CCWin;
namespace SNPAD
{
    public partial class FrmRptSD : Form
    {  
        public DataTable DT;
        public OleDbDataAdapter ODA;
        public FrmRptSD()
        {
            InitializeComponent();
        }

        private void FrmRptSD_Load(object sender, EventArgs e)
        {
            //    OleDbDataAdapter da = new OleDbDataAdapter();
            //    System.Data.DataSet ds = new System.Data.DataSet();

            //    ds.Clear();
            //    da.SelectCommand = new OleDbCommand("select PL_Code,PL_Desc from jC_prodline", OleDbHelper3.m_conn);
            //    da.Fill(ds, "Prodline");

            //    DataRow row = ds.Tables["Prodline"].NewRow();
            //    row[0] = ""; row[1] = "全部";
            //    ds.Tables["Prodline"].Rows.Add(row);
            //    cmbPL.DataSource = ds.Tables[0];
            //    cmbPL.DisplayMember = ds.Tables[0].Columns[1].Caption; //"PL_Desc";
            //    cmbPL.ValueMember = ds.Tables[0].Columns[0].Caption; //"PL_Code";
            //    cmbPL.SelectedIndex = cmbPL.Items.Count - 1;

            //    OleDbDataAdapter da2 = new OleDbDataAdapter();
            //    System.Data.DataSet ds2 = new System.Data.DataSet();

            //    da2.SelectCommand = new OleDbCommand("select model_Code,model_Desc from jC_model", OleDbHelper3.m_conn);
            //    da2.Fill(ds2, "model");
            //    DataRow row2 = ds2.Tables["model"].NewRow();
            //    row2[0] = ""; row2[1] = "全部";
            //    ds2.Tables["model"].Rows.Add(row2);
            //    cmbModel.DataSource = ds2.Tables[0];
            //    cmbModel.DisplayMember = ds2.Tables[0].Columns[1].Caption; //"PL_Desc";
            //    cmbModel.ValueMember = ds2.Tables[0].Columns[0].Caption; //"PL_Code";
            //    cmbModel.SelectedIndex = cmbModel.Items.Count - 1;

            //    //ds=null;
            //    //row = null;
            //    //da = null;
            //    //cmbModel.DataSource = OleDbHelper3.ExecuteDataTable("select * from jC_model");
            //    //cmbModel.DisplayMember = "model_Desc";
            //    //cmbModel.ValueMember = "model_Code";

            //    ////cmbModel.SelectedIndex = 0;
            //    dateTimeInput2.Value = DateTime.Today;
            //    dateTimeInput1.Value = DateTime.Today;
            skinDataGridView3.AutoGenerateColumns = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {


            //string values = "select model_code ,OutQty,OutCartonQty,sysLotNo,sysLotQty,QtyPerCarton,sysCartonQty,QtyInRestCarton,RealLotno,RealLotQty from inventory";
            string values = "select * from inventory";

            //if (cmbModel.SelectedValue.ToString().Trim().Length > 0)
            //{
            //    values += " and a.model_code='" + cmbModel.SelectedValue.ToString() + "'";
            //}
            //if (cmbPL.SelectedValue.ToString().Trim().Length > 0)
            //{
            //    values += " and a.pl_code='" + cmbPL.SelectedValue.ToString() + "'";
            //}



            ////DataTable dt = OleDbHelper3.ExecuteDataTable(values);
            ////            skinDataGridView3.DataSource = dt;

            ODA = new OleDbDataAdapter(values , OleDbHelper3.Conn);
            DT = new DataTable();

            ODA.Fill(DT);//将查到的数据传到DataTable中
           skinDataGridView3.DataSource = DT;

        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            //Excel.SaveAs(skinDataGridView3);

            Excel.ExportExcel("", skinDataGridView3);
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void dateTimeInput1_Click(object sender, EventArgs e)
        {

        }

        private void skinDataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
        }

        private void skinDataGridView3_DoubleClick(object sender, EventArgs e)
        {
            
        }

        

        private void skinButton2_Click(object sender, EventArgs e)
        {
            //skinDataGridView3.Columns[i].ReadOnly = true;
            ////int count = Convert.ToInt32(skinDataGridView3.Rows.Count.ToString());
            ////for (int i = 0; i < count; i++)
            ////{
            ////    //如果DataGridView是可编辑的，将数据提交，否则处于编辑状态的行无法取到
            ////    skinDataGridView3.EndEdit();

            ////    DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)skinDataGridView3.Rows[i].Cells["cbCheck"];
            ////    Boolean flag = Convert.ToBoolean(checkCell.Value);
            ////    if (flag == true)     //查找被选择的数据行
            ////    {
            ////        //从 DATAGRIDVIEW 中获取数据项
            ////        string AutoID = skinDataGridView3.Rows[i].Cells["AutoID"].Value.ToString().Trim();

            ////    }
               
            ////}
            OleDbCommandBuilder ODB = new OleDbCommandBuilder(ODA);
            ODA.UpdateCommand = ODB.GetUpdateCommand();
            ODA.Update(DT);
        }

        private void skinDataGridView3_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            //如果DataGridView是可编辑的，将数据提交，否则处于编辑状态的行无法取到
             int i=  skinDataGridView3.CurrentCell.ColumnIndex;
            if (!skinDataGridView3.Columns[i].Name.ToString().Equals("cbCheck")) return;
              skinDataGridView3.CurrentRow.Cells["IsChecked"].Value = true;

             skinDataGridView3.EndEdit();
            OleDbCommandBuilder ODB = new OleDbCommandBuilder(ODA);
            ODA.UpdateCommand = ODB.GetUpdateCommand();
            ODA.Update(DT);
            //DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)skinDataGridView3.Rows[i].Cells["cbCheck"];
            //    Boolean flag = Convert.ToBoolean(checkCell.Value);
            //    if (flag == true)     //查找被选择的数据行
            //    {
            //       string AutoID = skinDataGridView3.Rows[i].Cells["AutoID"].Value.ToString().Trim();

            //    }
            ////skinDataGridView3.BeginEdit( true)/*;*/
       
        }
    }
}
